import processing.xml.*; 

public class XMLReader{
  PApplet pApplet;
  Vector<Object> floors = new Vector<Object>();
  int numFloors;
  
  ArrayList<Model> m_models = new ArrayList<Model>();
  
  XMLReader(PApplet pApplet){
    this.pApplet = pApplet;
    
    XMLElement xml = new XMLElement(this.pApplet, "floors.xml");
    this.numFloors = xml.getChildCount();
    for (int i = 0; i < this.numFloors; i++) {
      XMLElement Floor = xml.getChild(i);
      for (int j = 0; j < Floor.getChildCount(); j++) {
        XMLElement each = Floor.getChild(j);
        String img = each.getStringAttribute("src"); 
        String caption = each.getStringAttribute("alt");
        this.floors.add(img);
        this.floors.add(caption);
      }
    }
  }
  
  Vector<Object> getFloors(){ 
    return this.floors; 
  }
  
  int getFloorsInt(){
    return this.numFloors;  
  }
  
  
  ArrayList<Model> getSnifferModels(){    
    XMLElement xml = new XMLElement(this.pApplet, "models.xml");
    int childs = xml.getChildCount();
    for (int i = 0; i < childs; i++) {
      XMLElement models = xml.getChild(i);
      for (int j = 0; j < models.getChildCount(); j++) {
        XMLElement each = models.getChild(j);
        Model model = new Model(); 
        String name = each.getStringAttribute("name");
        String src = each.getStringAttribute("src");
        int deg = each.getIntAttribute("rotate");
        model.name(name);
        model.src(src);
        model.rotateDeg(deg);
        m_models.add(model);
      }
    }
    return m_models;
  }
}
